﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Reflection;
using Kokomo.PeInspector.Reflection.Disassembly;

namespace Kokomo.PeInspector.Reflection
{
	/// <summary>
	/// Represents a dependency graph.
	/// </summary>
	/// <remarks>
	/// A dependency graph describes the dependencies of members within the graph,
	/// independent of the visual representation.
	/// The <see cref="DependencyDelegate"/> defines the structure of the graph,
	/// which may contain one level or multiple levels.
	/// </remarks>
	public class DependencyGraph
	{
		/// <summary>
		/// Gets the root, or origin, of the graph.
		/// </summary>
		public MemberInfo RootMember { get; private set; }
		/// <summary>
		/// Gets the delegate that enumerates the dependencies of a member.
		/// </summary>
		public Func<MemberInfo, ProgressInfo, IEnumerable<MemberInfo>> DependencyDelegate { get; private set; }

		/// <summary>
		/// Initializes a new instance of <see cref="DependencyGraph"/>.
		/// </summary>
		/// <param name="rootMember">The root, or origin, of the graph.</param>
		/// <param name="dependencyDelegate">The delegate that enumerates the dependencies of a member.</param>
		public DependencyGraph(
			MemberInfo rootMember,
			Func<MemberInfo, ProgressInfo, IEnumerable<MemberInfo>> dependencyDelegate
			)
		{
			if (rootMember == null) throw new ArgumentNullException("rootMember");
			if (dependencyDelegate == null) throw new ArgumentNullException("dependencyDelegate");

			this.RootMember = rootMember;
			this.DependencyDelegate = dependencyDelegate;
		}
	}
}
